<?php
class Default_Model_UserTour extends Zend_Db_Table{

	protected $_name = USER_TOUR_TABLE;
	protected $_primary = 'user_tour_id';

	private $USER_TOUR_ID = 'user_tour_id';
	private $USER_ID = 'user_id';
	private $TOUR_ID = "tour_id";
	private $USER_TOUR_STATUS = "status";
	private $USER_TOUR_ROLE = "role";

	protected $db;

	public function __construct(){
		//Goi ket noi voi Zend Db
		$this->db = Zend_Registry::get('connectDB');
	}

	protected $_messageError = null;

	public function getTourByUser($userId) {
		$select = $this->db->select()->from(USER_TOUR_TABLE)->where($this->USER_ID.' = ?',$userId);
		$result  = $this->db->fetchAll($select);
		return $result;
	}
	
	public function getUserTour($userId) {
		$select = $this->db->select()->from(USER_TOUR_TABLE)->where($this->USER_ID.' = ?',$userId)->where($this->USER_TOUR_ROLE.' = ?',1);
		$result  = $this->db->fetchAll($select);
		return $result;
	}
	
	public function getUserCreateByTour($tourId) {
		$select = $this->db->select()->from(USER_TOUR_TABLE)->where($this->TOUR_ID.' = ?',$tourId)->where($this->USER_TOUR_ROLE.' = ?',1);
		$result  = $this->db->fetchAll($select);
		return $result;
	}

	// Xoa thong tin user tour
// 	public function deleteUserTourById($userTourId){
// 		try {
// 			$this->db->delete(USER_TOUR_TABLE,$this->USER_TOUR_ID.' = ' . $userTourId);
// 			return true;
// 		} catch (Exception $e) {
// 			$this->_messageError = $e->getMessage();
// 			return false;
// 		}
// 	}
	
	public function deleteUserTourByTourId($tourId){
		try {
			$this->db->delete(USER_TOUR_TABLE,$this->TOUR_ID.' = ' . $tourId);
			return true;
		} catch (Exception $e) {
			$this->_messageError = $e->getMessage();
			return false;
		}
	}

	public function getError(){
		return $this->_messageError;
	}
}